package com.netdisk.controller.interceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.omg.PortableInterceptor.SUCCESSFUL;
import org.springframework.stereotype.Component;

import com.netdisk.entity.User;
import com.netdisk.service.impl.FileSystemService;
import com.netdisk.service.impl.UserService;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import javax.servlet.http.HttpSession;
/**
 * 
 * @author chenlong
 * 
 * 2013-5-18 7:59:08
 *
 */
import com.opensymphony.xwork2.ActionInvocation;
@Component("contextIterceptor")
public class ContextIterceptor extends AbstractInterceptor {
	
	private UserService userService;
	
	@Resource(name="userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	FileSystemService fileSystemService;
	
	@Resource(name="fileSystemService")
	public void setFileSystemService(FileSystemService fileSystemService) {
		this.fileSystemService = fileSystemService;
	}



	@Override
	public String intercept(ActionInvocation ai) throws Exception {
		HttpServletRequest request = (HttpServletRequest) ai.getInvocationContext()
				.get(ServletActionContext.HTTP_REQUEST);
		
		HttpSession session = request.getSession();
		User user = userService.findById("20456a6bc45147878b9ae94200328a03");
		session.setAttribute("user", user);
		session.setAttribute("logined", "enterprise");
		//fileSystemService.f
		//session.setAttribute("parrentDir", value);
		//session.setAttribute("currentDir", value);
		return ai.invoke();
	}
	
}
